package com.hzdl.dao.impl;

import com.hzdl.dao.AccountDao;
import com.hzdl.domain.Account;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.sql.SQLException;
import java.util.List;

/**
 * @author ：Reus CAI
 * @date ：Created in 2020/12/15 10:23
 * @description：
 * @modified By：
 * @version: $
 */


@Repository("accountDao")
public class AccountDaoImpl implements AccountDao {


    @Resource(name = "queryRunner")
    private QueryRunner queryRunner;


    public List<Account> findAll() throws SQLException {
        return queryRunner.query("select * from account", new BeanListHandler<Account>(Account.class));
    }

    public Account findById(Integer id) throws SQLException {
        return queryRunner.query("select * from account where id = ?", new BeanHandler<Account>(Account.class), id);
    }


    public void save(Account account) throws SQLException {
        queryRunner.update("insert into account values(null,?,?)", account.getName(), account.getMoney());

    }

    public void update(Account account) {

    }

    public void delete(Integer id) {

    }

    public void save() {

    }
}
